package main.java.indi.zyj.sort;

public class QuickSort {

    public static void quickSort(int[] stock, int low, int high) {

        if (low < high) {
            int mid = getMid(stock, low, high);
            quickSort(stock, low, mid - 1);
            quickSort(stock, mid + 1, high);
        }

    }

    private static int getMid(int[] stock, int low, int high) {

        int temp = stock[low];
        while (low < high) {
            while (low < high && stock[high] >= temp) high--;
            stock[low] = stock[high];
            while (low < high && stock[low] <= temp) low++;
            stock[high] = stock[low];
        }
        stock[low] = temp;
        return low;
    }


    public static void main(String[] args){
        int[] arr = {10, 7, 2, 4, 7, 62, 3, 4, 2, 1, 8, 9, 19};
        quickSort(arr, 0, arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}